﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}

<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
@* <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet">
</head> *@
<body>
    
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">负责人</label>
                    <div class="layui-input-block">
                        <select name="city" id="responsible" lay-filter="testSelect">
                            <option value="">请选择负责人类型</option>
                            <option value="张三">张三</option>
                            <option value="李四">李四</option>
                            <option value="王五">王五</option>
                            <option value="赵六">赵六</option>
                        </select>
                    </div>
                    <label class="layui-form-label">分娩日期</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="date" id="ewesGiveBirthTime" class="layui-input">
                    </div>



                    <button type="button" class="layui-btn layui-bg-red" onclick="Add()">新增</button>

                </div>


            </div>


            <table class="layui-table">
                <thead>
                    <tr>
                        <td>耳号</td>
                        <td>妊检天数</td>
                        <td>分娩难易</td>
                        <td>肥羊批次</td>
                        <td>母性</td>
                        <td>泌乳</td>
                        <td>乳房炎</td>
                        <td>窝号</td>
                        <td>健羔数</td>
                        <td>弱羔数</td>
                        <td>畸形数</td>
                     </tr>

                     <tr>
                        <td>死胎数</td>
                        <td>木乃伊数</td>
                        <td>畸胎数</td>
                         <td>活羔数</td>
                          <td>窝总重（公斤）</td>
                        <td>性别</td>
                        <td>当前栋舍</td>
                        <td>当前栏位</td>
                        <td>转入栋舍</td>
                        <td>转入栏位</td>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>
                           @*  耳号 *@
                            <select id="earBugles" lay-filter="testSelect">
                                <option value="">请选择</option>
                            </select>
                        </td>
                        @*  妊检天数 *@
                        <td> <input type="text" id="pregnancyDays" class="layui-input"></td>
                        @*  分娩难易 *@
                        <td>
                            <input type="text" id="parturitionDifficulty" class="layui-input">
                        </td>
                        @*  肥羊批次 *@
                        <td> <input type="text" id="fatSheepBatch" class="layui-input"></td>
                        @*  母性 *@
                        <td> <input type="text" id="maternalInstinct" class="layui-input"></td>
                        @*  泌乳 *@
                        <td> <input type="text" id="lactation" class="layui-input"></td>
                        @*  乳房炎 *@
                        <td> <input type="text" id="mastitis" class="layui-input"></td>
                        @*  窝号 *@
                        <td> <input type="text" id="nestNumber" class="layui-input"></td>
                        @*  健羔数 *@
                        <td> <input type="text" id="healthyLambNums" class="layui-input"></td>
                        @*  弱羔数 *@
                        <td> <input type="text" id="weakLambsNums" class="layui-input"></td>
                        @*  畸形数 *@
                        <td> <input type="text" id="deformityNums" class="layui-input"></td>
                    </tr>

                    <tr>
                        @*  死胎数 *@
                        <td> <input type="text" id="stillbirthNums" class="layui-input"></td>
                        @*  木乃伊数 *@
                        <td> <input type="text" id="mummificationNums" class="layui-input"></td>
                        @*  畸胎数 *@
                        <td> <input type="text" id="teratogenesiNums" class="layui-input"></td>
                        @*  活羔数 *@
                        <td> <input type="text" id="livingLambs" class="layui-input"></td>
                        @*  窝总重（公斤） *@
                        <td> <input type="text" id="litterWeight" class="layui-input"></td>
                        @*  性别 *@
                        <td> <input type="text" id="sex" class="layui-input"></td>
                        @*  当前栋舍 *@
                        <td> <input type="text" id="cottageName" class="layui-input"></td>
                        @*  当前栏位 *@
                        <td> <input type="text" id="fieldName" class="layui-input"></td>
                        @*  转入栋舍 *@
                        <td>
                            <select id="cottageId" lay-filter="provincet">
                                <option value="">请选择</option>
                            </select>
                        </td>
                        @*  转入栏位 *@
                        <td>
                            <select id="field" lay-filter="city">
                                <option value="">请选择</option>
                            </select>
                        </td>
                      
                    </tr>
                </tbody>
            </table>


            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" class="layui-textarea" id=""></textarea>
                </div>
            </div>
        </div>

    </form>


    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script>
    


</body>

</html>

<script>
    layui.use('form', function () {
        var table = layui.table;
        var form = layui.form;
        var layer = layui.layer;

        //绑定耳号
        bangsheng1();
        //绑定栋舍
        bangsheng();

        FantearBugles();



        //获取耳号下拉框的值
        form.on('select(testSelect)', function (data) {
            FantearBugles(data.value); // data.value 返回选中的值
            console.log(data.value, 6666666666)
        });


        //绑定栋舍
        function bangsheng() {
            $.ajax({
                url: "http://localhost:5123/api/Cottage/CottageSecondaryQuery",
                data: JSON.stringify({}),
                type: "post",
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    console.log(res)
                    $.each(res.data, function () {
                        $("#cottageId").append(`<option value="${this.cottageId}">${this.cottageName}</option>`);
                    })
                    form.render('select'); // 重新渲染下拉框
                }
            })
        }

        //获取栋舍下拉框的值
        form.on('select(provincet)', function (data) {
            provincetId1 = data.value;
            console.log(provincetId1, 15152)
            $("#field").empty();
            $("#field").append('<option value="">请选择</option>');
            bangshi()

        });

        //绑定栏位
        function bangshi() {
            var cottageId = $("#cottageId").val();
            $.ajax({
                url: "http://localhost:5123/api/Field/GetFieldCottage",
                data: JSON.stringify({ cottageId: cottageId }),
                type: "post",
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    console.log(res.data)

                    $.each(res.data, function () {
                        $("#field").append(`<option value="${this.fieldId}">${this.fieldName}</option>`);
                    })
                    form.render('select'); // 重新渲染下拉框
                }

            })
        }

        //绑定耳号
        function bangsheng1() {

            $.ajax({
                url: "http://localhost:5269/api/SheepArchive/SheepEarBuglesQuery",
                data: JSON.stringify({}),
                type: "post",
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    console.log(res)
                    $.each(res.data, function () {
                        $("#earBugles").append(`<option value="${this.recordAuricle}">${this.recordAuricle}</option>`);
                    })
                    form.render('select'); // 重新渲染下拉框

                }

            })
        }

        //根据耳号加载数据
        function FantearBugles(aa) {
            //var recordAuricle = $("#earBugles").val();
            $.ajax({
                url: 'http://localhost:5269/api/SheepArchive/SheepEarBuglesBackFill',
                type: 'post',
                data: JSON.stringify({ recordAuricle: aa }),
                dataType: 'json',
                contentType: 'application/json',
                success: res => {
                    $(res.data).each(function () {
                        $("#sex").val(this.sex)
                        $("#cottageName").val(this.cottageName)
                        $("#fieldName").val(this.fieldName)
                    })
                    console.log(res, 88888)
                }
            })
        }

    })

    //分娩新增
    function Add() {
        var data = {
            //负责人
            responsible: $("#responsible").val(),
            //分娩日期
            ewesGiveBirthTime: $("#ewesGiveBirthTime").val(),
            //耳号
            earBugles: $("#earBugles").val(),
            //妊检天数
            pregnancyDays: $("#pregnancyDays").val(),
            //分娩难易
            parturitionDifficulty: $("#parturitionDifficulty").val(),
            //肥羊批次
            fatSheepBatch: $("#fatSheepBatch").val(),
            //母性
            maternalInstinct: $("maternalInstinct").val(),
            //泌乳
            lactation: $("#lactation").val(),
            //乳房炎
            mastitis: $("#mastitis").val(),
            //窝号
            nestNumber: $("#nestNumber").val(),
            //健羔数
            healthyLambNums: $("#healthyLambNums").val(),
            //弱羔数
            weakLambsNums: $("#weakLambsNums").val(),
            //畸形数
            deformityNums: $("#deformityNums").val(),
            //死胎数
            stillbirthNums: $("#stillbirthNums").val(),
            //木乃伊数
            mummificationNums: $("#mummificationNums").val(),
            //畸胎数
            teratogenesiNums: $("#teratogenesiNums").val(),
            //活羔数
            livingLambs: $("#livingLambs").val(),
            //窝总重（公斤）
            litterWeight: $("#litterWeight").val(),
            //性别
            sex: $("#sex").val(),
            //当前栋舍
            currentBuildings: $("#cottageName").val(),
            //当前栏位
            currentColumns: $("#fieldName").val(),
            //转入栋舍
            cottageId: $("#cottageId").val(),
            //转入栏位
            fieldId: $("#field").val(),
        }

        $.ajax({
            url: "http://localhost:5269/api/SheepArchive/EwesGiveBirthCreate",
            type: 'post',
            data: JSON.stringify(data),
            dataType: "json",
            contentType: "application/json",
            success: res => {
                if (res.code == 0) {
                    layer.msg('添加成功')
                    location.href = '/Birth/BreedingParturition/'

                }
                else {
                    layer.msg('保存失败')
                }
            }
        })
    }
</script>